<template>
  <div>
    <el-container v-if="!xiangqingshow">
      <el-header>
        <h1 class="title">设备管理</h1>

        <div class="sh">
          <p>报废中</p>
          <p>未使用</p>
          <p>使用中</p>
          <p>维修中</p>
        </div>
      </el-header>
      <el-container>
        <AsideView :name="true"> </AsideView>
        <MainView :datass="datas" :getnumbers="getnumbers" :getpages="getpages">
          <el-table-column slot="input" prop="id" label="设备编号" width="50">
            <input type="checkbox" name="" id="" />
          </el-table-column>
          <el-table-column slot="caozuo" prop="zip" label="操作" width="220">
            <template slot-scope="scope">
              <el-button
                @click="handleClick(scope.row)"
                type="text"
                size="small"
                >详情</el-button
              >

              <el-button
                type="primary"
                @click="genggaizhuangtai(scope.row)"
                size="small"
                >更改状态</el-button
              >
            </template>
          </el-table-column>
        </MainView>
      </el-container>
    </el-container>
    <xiang-qing v-else :xiangqing="xiangqing" :names="name"></xiang-qing>
    <!-- 状态改变 -->
    <el-dialog
      title="设置状态"
      :visible.sync="dialogVisible"
      width="30%"
      :before-close="handleClose"
    >
      <el-form :inline="true" class="demo-form-inline">
        <el-form-item label="选择状态">
          <el-select v-model="status">
            <el-option label="报废中" value="STATUS6" aria-selected></el-option>
            <el-option label="维修中" value="STATUS5"></el-option>
            <el-option label="使用中" value="STATUS4"></el-option>
            <el-option label="未使用" value="STATUS3"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="zhuantaigenggai">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import mixins from "../../mixin";
import AsideView from "../../components/AsideView.vue";
import MainView from "../../components/MainView.vue";

import XiangQing from "../../components/XiangQing.vue";
export default {
  mixins: [mixins],
  components: { AsideView, MainView, XiangQing },
  name: "GuanLi",
  data() {
    return {
      name: "设备管理详情",
      xiangqingshow: false,
      dialogVisible: false,
      xiangqing: {},
      datas: {},
      id: "",
      status: "",
      todata: {
        pageNo: "1",
        pageSize: "10",
        id: "",
        name: "",
        status: "",
        category: "",
      },
      zhuangtai: "",
    };
  },
  methods: {
    //跳转详情
    handleClick(row) {
      console.log(row);
      this.xiangqingshow = true;
      this.xiangqing = row;
    },
    // 数据查询
    // searchs() {
    //   this.$bus.$on("search", (data) => {
    //     console.log(data);
    //     this.todata = { ...this.todata, ...data };
    //     // console.log(this.todata);
    //     this.list();
    //   });

    //   // console.log(this.datas);
    // },
    // 隐藏详情，显示列表、
    showlist() {
      this.$bus.$on("fhlb", (data) => {
        this.xiangqingshow = data;
      });
    },
    // 数据请求
    // async list() {
    //   let res = await this.$axios({
    //     method: "post",
    //     url: "/equip-list",
    //     data: this.todata,
    //   });
    //   // console.log(res);

    //   this.datas = res.data.data;
    // },
    // 改变状态
    genggaizhuangtai(row) {
      // console.log(row);
      this.dialogVisible = true;
      this.id = row.id;
      // console.log(this.todata);
    },
    handleClose(done) {
      console.log(done);
      this.$confirm("确认关闭？");
      // .then((_) => {
      //   done();
      // })
      // .catch((_) => {});
    },
    async zhuantaigenggai() {
      this.dialogVisible = false;

      await this.$axios({
        method: "post",
        url: "/equip-set",
        data: {
          id: this.id,
          status: this.status,
        },
      })
        .then((res) => {
          console.log(res);

          console.log(typeof res.data.code);

          if (res.data.code == 0) {
            this.list();
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    // // 查询点击分页效果
    // getnumbers(num = "15") {
    //   this.todata.pageSize = num;
    //   this.list();
    // },
    // getpages(page = "1") {
    //   this.todata.pageNo = page;
    //   this.list();
    // },
  },
  mounted() {
    this.showlist();
    this.list();
    this.searchs();
    this.getpages();
    this.getnumbers();
  },
};
</script>

<style scoped lang="less">
.el-header {
  background-color: #fff;
  color: rgb(155, 152, 152);
  line-height: 60px;
  display: flex;
  justify-content: space-between;
  .title {
    width: 240px;
  }
  .el-button {
    flex: 1;
    text-align: left;
    font-size: 14px;
    font-weight: bold;
  }
  .sh {
    display: flex;
    font-size: 10px;
    p {
      margin-right: 20px;
      position: relative;

      &::after {
        content: "";
        display: block;
        width: 10px;
        height: 10px;
        background: red;
        position: absolute;
        top: 50% - 5px;
        right: -15px;
      }
      &:nth-child(2)::after {
        background: yellow;
      }
      &:nth-child(3)::after {
        background: rgb(0, 17, 255);
      }
      &:nth-child(4)::after {
        background: rgb(174, 0, 255);
      }
    }
  }
}

.el-aside {
  background-color: #d3dce6;
  color: #333;
  text-align: left;
  // line-height: 200px;
  padding-right: 5px;
  .el-input__inner {
    width: 90%;
    height: 30px;
    padding-right: 0;
    padding: 0 5px;
    .el-input__suffix {
      right: 15px;
    }
  }
}
.el-container {
  width: 100%;
  height: 100%;
  overflow: hidden;
}
.el-main {
  width: 100%;

  background-color: #e9eef3;
  color: #333;
  padding: 0;
}

// body > .el-container {
//   margin-bottom: 40px;
// }

.el-table .el-table__cell {
  padding: 8px 0;
}
.table_box {
  width: 100%;
  height: 85%;
}
</style>